//
//  JieSuoView.m
//  AILove
//
//  Created by 甘世清 on 2023/12/30.
//

#import "JieSuoView.h"
#import "ChongZhiView.h"
#import "JieGuoView.h"
@implementation JieSuoView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = UIColor.clearColor;
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
    UIVisualEffectView* visualView = [[UIVisualEffectView alloc]initWithEffect:effect];
     visualView.frame =CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT);
      visualView.alpha = 0.92;
     [self addSubview:visualView];
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = SQHexColor(@"#FFFFFF", 0.24);
    bgView.layer.cornerRadius = 12;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(295);
        make.height.mas_equalTo(210);
        make.centerX.centerY.equalTo(self);
    }];
    UILabel * oneLabel= [[UILabel alloc]init];
    oneLabel.text = SQNSLocalString(@"解锁相册");
    oneLabel.textColor = SQColor(@"#FFFFFF");
    oneLabel.font = FONT_BOLD(18);
    [bgView addSubview:oneLabel];
    [oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(20);
        make.centerX.equalTo(bgView);
        make.height.mas_equalTo(18);
    }];
    _guanbi = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(15, 15) midmargin:0];
    _guanbi.image = SQGetImage(@"退出图标");
    [self addSubview:self.guanbi];
    [self.guanbi mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(bgView.mas_bottom);
            make.size.mas_equalTo(45);
    }];
    
    YYLabel * label3 = [[YYLabel alloc]initWithFrame:CGRectMake(16, 62, 263, 72)];
    label3.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    label3.textAlignment = NSTextAlignmentCenter;
    label3.numberOfLines = 0;
    [bgView addSubview:label3];
    NSDictionary *attributes = @{NSFontAttributeName:FONT_MEDIUM(16) , NSForegroundColorAttributeName: SQColor(@"#FFFFFF")};
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:SQNSLocalString(@"是否花费40钻石，解锁您选择的相册图片，解锁后的相片可以替换为角色人物封面图片") attributes:attributes];
   
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:SQNSLocalString(@"花费40钻石")] color:SQColor(@"#F9DB8F") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
       
    }];
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:SQNSLocalString(@"角色人物封面图片")] color:SQColor(@"#F9DB8F") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        
    }];
    
    label3.attributedText = text;
    
    HeaderView * btn = [[HeaderView alloc]init];
    btn.font = FONT_MEDIUM(16);
    btn.text = SQNSLocalString(@"确定解锁");
    btn.layer.cornerRadius = 4;
    btn.headerImage.image = SQGetImage(@"按钮背景");
    [btn.btn addTarget:self action:@selector(SQ_buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgView.mas_bottom).offset(-20);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(263);
        make.centerX.equalTo(bgView);
    }];
    
}
-(void)SQ_buttonClick{

    if ([UserModel share].diamond < 40) {
        [self SQ_zuanshi];
    } else {
        NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
        [dic setObject:self.model.userId forKey:@"photoId"];
        [HttpTool post:Url18 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
            [self SQ_goumaichenggong];
        } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
            [YJProgressHUD showMsgWithoutView:httpModel.message];
        }];
      
    }
    
}
-(void)SQ_zuanshi{
    ChongZhiView * vc = [[ChongZhiView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:nil
                                             popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    pop.hemStyle = LSTHemStyleCenter;
//    pop.isStack = YES;
    [pop pop];
    LSTPopViewWK(pop)
    [vc.guanbi setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [wk_pop dismiss];
    }];
    [vc setCZBlock:^(BOOL isOk) {
        [wk_pop dismiss];
    }];
}
-(void)SQ_goumaichenggong{
    JieGuoView * vc = [[JieGuoView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:nil
                                             popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    pop.hemStyle = LSTHemStyleCenter;
    pop.isStack = YES;
    [pop pop];
    WS(weakSelf);
    LSTPopViewWK(pop)
    [vc setJGBlock:^{
        [wk_pop dismiss];
        if (weakSelf.jiesuoBlock) {
            weakSelf.jiesuoBlock();
        }
    }];

}

@end
